/**
 * @author: fangchaunzhi
 * @descripition: 数丰智能科技map管理
 * @date: created in 15:23 2019/9/20
 * @modify: fangchuanzhi.
 */
//////////////////////////////暂时不要动这块代码////////////////////////////////////////
// import mapboxgl from 'mapbox-gl'
// import mapboxgl from '@cgcs2000/mapbox-gl'

// import mapboxgl from '../../../static/mapbox-gl-enhance-sp'  //超图支持EPSG:4490有问题
// import '@supermap/iclient-mapboxgl/dist/iclient9-mapboxgl-es6.min'
//////////////////////////////引入绘制////////////////////////////////////////
export default {
  map: {},
  // 屏幕坐标
  point: {},
  // 地理坐标
  lngLat: {},
  Draw:{},
  // 地图初始化
  init(id) {
    mapboxgl.accessToken = '<your access token here>';
    //初始化地图对象   添加两个标记图层  baselayer-tag   overlayer-tag   底图在baselayer-tag之前，专题图在  overlayer-tag之前
    const map = new mapboxgl.Map({
      container: id,
      style: {
        "version": 8,
        "sources": {
          "baselayer-tag-source":{
            "type": "geojson",
            "data": {
              "type": "Feature",
              "geometry": {
                "type": "Polygon",
                "coordinates": [[]]
              }
            }
          },
          "overlayer-tag-source":{
            "type": "geojson",
            "data": {
              "type": "Feature",
              "geometry": {
                "type": "Polygon",
                "coordinates": [[]]
              }
            }
          }
        },
        "layers": [   //两个用来做标记的图层，暂时只能这样简单处理，mapbox没有全局调整顺序的方式
          {
            "id": "baselayer-tag",
            "type": "fill",
            "source": "baselayer-tag-source",
            "paint": {
              "fill-color": "rgba(0, 0, 255, 0.1)",
              'fill-outline-color': "red",
            }
          },
          {
            "id": " overlayer-tag",
            "type": "fill",
            "source": "overlayer-tag-source",
            "paint": {
              "fill-color": "rgba(0, 0, 255, 0.1)",
              'fill-outline-color': "red",
            }
          }]
      },
      doubleClickZoom: false,			// 禁止双击缩放
      zoom: 5,
      minZoom:0,
      maxZoom:16,
      crs:"EPSG:4490",  //除外网外其他统一使用
      center: [104.081526,30.655797],
      preserveDrawingBuffer: true//允许地图导出为图片
    });
    map["overlayers"] = {}; // 存放overlayers
    map["overlayerInfos"] = {}; // 存放overlayer的相关信息
    map.clusterLayerDBclick = false;  // 用于聚集图双击下钻标识
    this.map = map;
    const _this = this;

    map.on("mousemove", e => {
      _this.point = e.point;
      _this.lngLat = e.lngLat;
    });
    // 初始化地图工具栏
    // mapTool.init(map);
  },
  /**
   * 获取鼠标屏幕坐标
   * @returns {default.point|{}}
   */
  getMousePoint() {
    return this.point;
  },
  /**
   * 获取鼠标地理坐标
   * @returns {default.lngLat|{}}
   */
  getMouseLngLat() {
    return this.lngLat;
  },
  /**
   * 获取地图
   * @returns {default.map|{}}
   */
  getMap() {
    return this.map;
  },
  /**
   * 保存一下Draw工具方便全局获取
   * @param Draw
   */
  setDraw(Draw){
    this.Draw = Draw;
  },
  /**
   * 获取绘制工具对象
   * @returns {default.Draw|{}}
   */
  getDraw(){
    return this.Draw;
  }
};
